package edu.gdkm.controller;

import edu.gdkm.pojo.Users;
import edu.gdkm.service.IUsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/users")
public class UsersController {
    @Autowired
    IUsersService iUsersService;
    @RequestMapping("/login")
    public String login(Users users, Model model, HttpSession session){
        int result=iUsersService.login(users.getName(),users.getPwd());
        if(result==2){
            session.setAttribute("USER_SESSION",users);
            return "main";
        }else if(result==1) {
            session.setAttribute("USER_SESSION",users);
            return "bindstudent";
        }else{
            model.addAttribute("msg","账号密码错误");
            return "forward:/WEB-INF/jsp/index.jsp";
        }
    }


}
